package fr.afcepf.ai85.gepeto.service;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import fr.afcepf.ai85.ent.PeriodeInscription;
import fr.afcepf.ai85.ent.TypeActivite;
import fr.afcepf.ai85.hibernate.util.HibernateUtil;

public class ServiceActivite {

	public static void main(String[] args) {

		for (TypeActivite t : listeActivites()) {

			System.out.println(t);

		}
		System.out.println(getIdSoirByNom());

	}

	public static List<TypeActivite> listeActivites() {

		Session session = HibernateUtil.currentSession();
		Transaction tx = session.beginTransaction();

		Query hql1 = session.createQuery("FROM TypeActivite");

		List<TypeActivite> listeTypeAct = hql1.list();

		return listeTypeAct;
	}
	
	public static Integer getIdSoirByNom(){
		Session session = HibernateUtil.currentSession();
		Transaction tx = session.beginTransaction();
		Query sql =  session.createSQLQuery("SELECT id_activite FROM type_activite where type_activite.nom_activite = 'Accueil soir'");
		List<Integer> liste = sql.list();
		Integer idActivSoir = liste.get(0);
		HibernateUtil.closeSession();
		return idActivSoir;
	}
	public static Integer getIdCantineByNom(){
		Session session = HibernateUtil.currentSession();
		Transaction tx = session.beginTransaction();
		Query sql =  session.createSQLQuery("SELECT id_activite FROM type_activite where type_activite.nom_activite = 'Cantine'");
		List<Integer> liste = sql.list();
		Integer idActivCant = liste.get(0);
		HibernateUtil.closeSession();
		return idActivCant;
	}
	public static Integer getIdMatByNom(){
		Session session = HibernateUtil.currentSession();
		Transaction tx = session.beginTransaction();
		Query sql =  session.createSQLQuery("SELECT id_activite FROM type_activite where type_activite.nom_activite = 'Accueil matin'");
		List<Integer> liste = sql.list();
		Integer idActivMat = liste.get(0);
		HibernateUtil.closeSession();
		return idActivMat;
	}


}
